package com.quanquan.management.controller;

import DTO.image.Image;
import base.BaseConst;
import com.quanquan.management.service.ImageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 图片管理
 */

@Controller
@RequestMapping("/image")
public class ImageController extends ManagerBaseController{

    public static final Logger logger = LoggerFactory.getLogger(ImageController.class);

   @Autowired
   private ImageService imageService;

    /**
     * 后台查询或修改会员权益
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model) {
        Image iamge = imageService.list();
        model.addAttribute("pageObj", iamge);
        return "rightsAndInterests/list";
    }


    @RequestMapping(value = "/edit")
    public String edit(String imageId, Model model) {
        if (BaseConst.RequestMethod.GET.equals(this.request.getMethod())) {
            Image iamge = imageService.findById();
            model.addAttribute("editable", iamge);
            return "rightsAndInterests/form";
        }
        boolean update = imageService.update(imageId);
        if (update) {
            return "redirect:/image/list";
        }
        return null;
    }
}
